package com.hspedu.homework;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * @author LiuJinTao
 * @className Homework02
 * @date 2024/06/14 10:55
 * @description TODO
 */
public class Homework02 {
    public static void main(String[] args) {
        Car car1 = new Car("宝马", 400000);
        Car car2 = new Car("宾利", 5000000);

        ArrayList list = new ArrayList();
        list.add(car1);
        list.add(car2);
        System.out.println("list=" + list);

        list.remove(car1);
        System.out.println("list=" + list);

        System.out.println(list.contains(car1));
        System.out.println(list.contains(car2));

        System.out.println("list元素个数=" + list.size());

        System.out.println("list是否为空=" + list.isEmpty());

        list.clear();
        System.out.println("list=" + list);

        ArrayList list1 = new ArrayList();
        list1.add(car1);
        list1.add(car2);
        list.addAll(list1);
        System.out.println("list=" + list);
        System.out.println("list1=" + list1);

        System.out.println(list.containsAll(list1));

        list.removeAll(list1);
        System.out.println("list=" + list);
        System.out.println("list1=" + list1);

        System.out.println("=====迭代器=====");
        Iterator iterator = list1.iterator();
        while (iterator.hasNext()) {
            Object next =  iterator.next();
            System.out.println((Car)next);
        }

        System.out.println("=====增强for=====");
        for (Object o : list1) {
            System.out.println((Car)o);
        }

    }
}

class Car {
    private String name;
    private double price;

    public Car(String name, double price) {
        this.name = name;
        this.price = price;
    }

    @Override
    public String toString() {
        return "Car{" +
                "name='" + name + '\'' +
                ", price=" + price +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }
}